var ajaxHelper = require("../../utils/ajaxhelp");
let token = wx.getStorageSync('token');
const serviceUrl = getApp().globalData.serviceUrl;


const getCommunityByPAC = (provinceName, cityName, areaName) => {
	token = wx.getStorageSync('token');
	return ajaxHelper.promiseRequst(serviceUrl + "/api/Community/QueryCommunityByPosition", {
		'Authorization': 'Bearer ' + token
	}, "GET", {
		province: provinceName,
		city: cityName,
		county: areaName
	})
}

const getCommunityById = (id) => {
    token = wx.getStorageSync('token');
	return ajaxHelper.promiseRequst(serviceUrl + "/api/Community/GetCommunityById", {
		'Authorization': 'Bearer ' + token
	}, "GET", {
		communityId: id
	})
}

//  const getCommunityByName=(provinceName,cityName,areaName,name)=>
//  {
//     return  ajaxHelper.promiseRequst(serviceUrl+"/api/Community/GetCommunityByName",
//     {'Authorization':'Bearer '+token},"GET",{province:provinceName,city:cityName,county:areaName,communityName:name})
//  }
const getCommunityByName = (community = {}) => {
	token = wx.getStorageSync('token');
	return ajaxHelper.promiseRequst(serviceUrl + "/api/Community/QueryCommunityByStreet", {
		'Authorization': 'Bearer ' + token
	}, "POST", community)
}
const modCommunityById = (community = {}) => {
	token = wx.getStorageSync('token');
	return ajaxHelper.promiseRequst(serviceUrl + "/api/Community/Post", {
		'Authorization': 'Bearer ' + token
	}, "Post", community)
}
const addCommunityById = (community = {}) => {
	token = wx.getStorageSync('token');
	return ajaxHelper.promiseRequst(serviceUrl + "/api/Community/Put", {
		'Authorization': 'Bearer ' + token
	}, "Post", community)
}
const GetStreetByPCA = (provinceName, cityName, areaName) => {
	token = wx.getStorageSync('token');
	return ajaxHelper.promiseRequst(serviceUrl + "/api/Street/GetStreetByPCA", {
		'Authorization': 'Bearer ' + token
	}, "GET", {
		provinceName: provinceName,
		cityName: cityName,
		areaName: areaName
	})
}

const getPCANameById = (provinceid, cityid, areaid) => {
	token = wx.getStorageSync('token');
	return ajaxHelper.promiseRequst(serviceUrl + "/api/Province/QueryPCANameById", {
		'Authorization': 'Bearer ' + token
	}, "GET", {
		provinceid: provinceid,
		cityid: cityid,
		areaid: areaid
	})
}
module.exports = {
	getPCANameById,
	getCommunityByPAC,
	getCommunityById,
	getCommunityByName,
	modCommunityById,
	addCommunityById,
	GetStreetByPCA
}
